package base;

import java.security.KeyStore.Entry;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

/*
 * 
 *  统计字符出现次数
 *  只出现一次的字符
 *  取出字符串中的数字与日期
 * 
 * */
public class DealStrings {

	public static void main(String[] args) {
		//getStringsCount();
		//getOnetimeString();
		//getNumber();
		//getDate();
		getStringsCount2();
		
	}
     
	/*    统计字符出现次数  */
	private static void getStringsCount() {
		Scanner sc =new Scanner(System.in);
		System.out.println("请输入一个字符串");
		String s =sc.nextLine();
		System.out.println("请输如需要统计的单个字符：");
		String ch =sc.nextLine();
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == ch.charAt(0)) {
				count++;
			}

		}
		System.out.println(ch.charAt(0) + " 出现的次数为：" + count+" 次");
	}
	
	
	private static void getStringsCount2() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个字符串");
		String s = sc.nextLine();
		char[] ch = s.toCharArray();
		int count = 0;
		Map map = new HashMap();
		for (int i = 0; i < ch.length; i++) {
			for (int j = 0; j < s.length(); j++) {
				if (ch[i] == s.charAt(j)) {
					map.put(s.charAt(i), ++count);
				}
			}
			count = 0;
		}
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry<Character, Integer> en = (java.util.Map.Entry<Character, Integer>) it.next();
			System.out.println(en.getKey() + "......" + en.getValue());
		}

	}

	       /*只出现一次的字符*/
	private static void getOnetimeString() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个字符串");
		String s = sc.nextLine();
		sc.close();
		int[] count = new int[s.length()];
		for (int i = 0; i < s.length(); i++) {
			for (int j = 0; j < s.length(); j++) {
				if (s.charAt(i) == s.charAt(j)) {
					count[i]++;
				}
			}
		}
		System.out.println("只出现一次的字符为：");
		for (int i = 0; i < count.length; i++) {
			if (count[i] == 1) {
				System.out.print(s.charAt(i)+"\t");
			}
		}
	}

	/*  取出字符串中的数字   */
    private static void getNumber(){
    	Scanner sc = new Scanner(System.in);
    	System.out.println("请输入一个字符串");
		String s = sc.nextLine();
         String regx="\\D*";
     String[] num =s.split(regx);
     System.out.println("截取到的数字为：");
     for(String i:num){
    	 System.out.print(i);
     }
    }
   
	/* 取出字符串中的日期 */
	private static void getDate(){
		Scanner sc =new Scanner(System.in);
		System.out.println("输入一个字符串：");
		String s=sc.nextLine();
		String regx="[1-9]{1}\\d{3}(-|/){1}\\d{1,2}(-|/){1}\\d{1,2}";
		Pattern pattern = Pattern.compile(regx);
		Matcher matcher = pattern.matcher(s);
		String date = null;
		if (matcher.find()) {
			date = matcher.group();
			System.out.println("截取到的日期为："+date);
		}
		else{
			System.out.println("输入的字符串中没有日期格式的字符");
		}
	}
	
	private static void getDate2(){
		Scanner sc =new Scanner(System.in);
		System.out.println("输入一个字符串：");
		String s=sc.nextLine();
		String regx="";
		Pattern pattern = Pattern.compile(regx);
		Matcher matcher = pattern.matcher(s);
		if(matcher.find()){
			
		}
		
	}
	
}
